package org.eae.eldf.framework.redis;

import java.util.List;

import org.eae.eldf.framework.redis.serializer.ObjectRedisSerializer;
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/******************************************************************************
 * @File name   :      ListRedisTemplate.java
 *
 * @Author      :      fxm
 *
 * @Date        :      2016-7-6
 *
 * @Copyright Notice: 
 * Copyright (c) 2016 Efast Serv. All  Rights Reserved.
 * This software is published under the terms of the Efast Software
 * License version 1.0, a copy of which has been included with this
 * distribution in the LICENSE.txt file.
 * 
 * 
 * ----------------------------------------------------------------------------
 * Date                   Who         Version        Comments
 * 2016-7-6 下午5:47:35        fxm     1.0            Initial Version
 *****************************************************************************/
public class ObjectRedisTemplate extends RedisTemplate<String, Object>{

	public ObjectRedisTemplate(){
		RedisSerializer<Object> objectSerializer = new ObjectRedisSerializer();
		//JdkSerializationRedisSerializer objectSerializer = new JdkSerializationRedisSerializer();
		setKeySerializer(new StringRedisSerializer());
		setValueSerializer(objectSerializer);
		setHashKeySerializer(new StringRedisSerializer());
		setHashValueSerializer(objectSerializer);
	}
	
	/**
	 * Constructs a new <code>StringRedisTemplate</code> instance ready to be used. 
	 *
	 * @param connectionFactory connection factory for creating new connections
	 */
	public ObjectRedisTemplate(RedisConnectionFactory connectionFactory) {
		this();
		setConnectionFactory(connectionFactory);
		afterPropertiesSet();
	}
	
	protected RedisConnection preProcessConnection(RedisConnection connection, boolean existingConnection) {
		return new DefaultStringRedisConnection(connection);
	}
}
